# use normal make for this Makefile
#
# Makefile for building user programs to run on top of Nachos
#
# Several things to be aware of:
#
#    Nachos assumes that the location of the program startup routine (the
# 	location the kernel jumps to when the program initially starts up)
#       is at location 0.  This means: start.o must be the first .o passed 
# 	to ld, in order for the routine "Start" to be loaded at location 0
#

# If you are running on SunOS 5.x machines, uncomment the next line
GCCDIR = /auto/home-scf-22/csci402/testgnu/decstation-ultrix/bin/
LDFLAGS = -T newscript -N
ASFLAGS = -mips1
CPPFLAGS = $(INCDIR)

# if you aren't cross-compiling:
# GCCDIR =
# LDFLAGS = -N -T 0
# ASFLAGS =
# CPPFLAGS = -P $(INCDIR)


CC = $(GCCDIR)gcc
AS = $(GCCDIR)as
LD = $(GCCDIR)ld
CPP = $(GCCDIR)cpp

INCDIR =-I../userprog -I../threads
CFLAGS = -G 0 -c $(INCDIR)

all: halt matmult sort testfiles locktest conditiontest forkexectest exectestmain exectestone exectesttwo threadtest1 forktest testFork

start.o: start.s ../userprog/syscall.h
	$(CPP) $(CPPFLAGS) start.s > strt.s
	$(AS) $(ASFLAGS) -o start.o strt.s
	rm strt.s

halt.o: halt.c
	$(CC) $(CFLAGS) -c halt.c
halt: halt.o start.o
	$(LD) $(LDFLAGS) start.o halt.o -o halt.coff
	../bin/coff2noff halt.coff halt

sort.o: sort.c
	$(CC) $(CFLAGS) -c sort.c
sort: sort.o start.o
	$(LD) $(LDFLAGS) start.o sort.o -o sort.coff
	../bin/coff2noff sort.coff sort

matmult.o: matmult.c
	$(CC) $(CFLAGS) -c matmult.c
matmult: matmult.o start.o
	$(LD) $(LDFLAGS) start.o matmult.o -o matmult.coff
	../bin/coff2noff matmult.coff matmult

testfiles.o: testfiles.c
	$(CC) $(CFLAGS) -c testfiles.c
testfiles: testfiles.o start.o
	$(LD) $(LDFLAGS) start.o testfiles.o -o testfiles.coff
	../bin/coff2noff testfiles.coff testfiles
	
locktest.o: locktest.c
	$(CC) $(CFLAGS) -c locktest.c
locktest: locktest.o start.o
	$(LD) $(LDFLAGS) start.o locktest.o -o locktest.coff
	../bin/coff2noff locktest.coff locktest
	
servertest.o: servertest.c
	$(CC) $(CFLAGS) -c servertest.c
servertest: servertest.o start.o
	$(LD) $(LDFLAGS) start.o servertest.o -o servertest.coff
	../bin/coff2noff servertest.coff servertest
	
conditiontest.o: conditiontest.c
	$(CC) $(CFLAGS) -c conditiontest.c
conditiontest: conditiontest.o start.o
	$(LD) $(LDFLAGS) start.o conditiontest.o -o conditiontest.coff
	../bin/coff2noff conditiontest.coff conditiontest
	
forkexectest.o: forkexectest.c
	$(CC) $(CFLAGS) -c forkexectest.c
forkexectest: forkexectest.o start.o
	$(LD) $(LDFLAGS) start.o forkexectest.o -o forkexectest.coff
	../bin/coff2noff forkexectest.coff forkexectest
	
exectestmain.o: exectestmain.c
	$(CC) $(CFLAGS) -c exectestmain.c
exectestmain: exectestmain.o start.o
	$(LD) $(LDFLAGS) start.o exectestmain.o -o exectestmain.coff
	../bin/coff2noff exectestmain.coff exectestmain
	
exectestone.o: exectestone.c
	$(CC) $(CFLAGS) -c exectestone.c
exectestone: exectestone.o start.o
	$(LD) $(LDFLAGS) start.o exectestone.o -o exectestone.coff
	../bin/coff2noff exectestone.coff exectestone
	
exectesttwo.o: exectesttwo.c
	$(CC) $(CFLAGS) -c exectesttwo.c
exectesttwo: exectesttwo.o start.o
	$(LD) $(LDFLAGS) start.o exectesttwo.o -o exectesttwo.coff
	../bin/coff2noff exectesttwo.coff exectesttwo
	
threadtest1.o: threadtest1.c
	$(CC) $(CFLAGS) -c threadtest1.c
threadtest1: threadtest1.o start.o
	$(LD) $(LDFLAGS) start.o threadtest1.o -o threadtest1.coff
	../bin/coff2noff threadtest1.coff threadtest1
	
forktest.o: forktest.c
	$(CC) $(CFLAGS) -c forktest.c
forktest: forktest.o start.o
	$(LD) $(LDFLAGS) start.o forktest.o -o forktest.coff
	../bin/coff2noff forktest.coff forktest
	
testFork.o: testFork.c
	$(CC) $(CFLAGS) -c testFork.c
testFork: testFork.o start.o
	$(LD) $(LDFLAGS) start.o testFork.o -o testFork.coff
	../bin/coff2noff testFork.coff testFork

clean:
	rm -f *.o *.coff
